<?php
declare(strict_types=1);

namespace App\Models\Admin\Image;

class Series extends \App\Models\Image\Series
{
    public static function getList(): array
    {
        $items = self::query()->where([
            ["is_show", "=", 1],
        ])->get(["uid", "title"]);
        $array = [];
        foreach ($items as $value) {
            $array[$value->uid] = $value->title;
        }
        return $array;
    }


    public function homeData(): array
    {
        $items = Series::query()->get(["uid", "title as name"])->toArray();
        $array = [];
        foreach ($items as $value) {
            $array[] = [
                "name"  => $value["name"],
                "value" => Image::query()->where("series_uid", "=", $value["uid"])->count("item_count")
            ];
        }
        //array_multisort(array_column($items, 'value'), SORT_DESC, $items);
        return $array;
    }
}
